package com.changdu.seatunnel.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.changdu.seatunnel.admin.entity.DataKafkaTemplate;
import com.changdu.seatunnel.admin.service.DataKafkaTemplateService;

@RestController
@RequestMapping("/api/datakafkatemplate")
public class DataKafkaTemplateController {
    
    @Autowired
    private DataKafkaTemplateService dataKafkaTemplateService;
    
    @GetMapping("/list")
    public List<DataKafkaTemplate> list(@RequestParam(required = false) Long syncConfigId) {
    	if (syncConfigId == null) return dataKafkaTemplateService.list();
    	
        return dataKafkaTemplateService.getTemplatesBySyncConfigId(syncConfigId);
    }
    
    @GetMapping("/{id}")
    public DataKafkaTemplate getById(@PathVariable Integer id) {
        return dataKafkaTemplateService.getById(id);
    }
    
    @PostMapping
    public boolean save(@RequestBody DataKafkaTemplate dataCenter) {
        return dataKafkaTemplateService.save(dataCenter);
    }
    
    @PutMapping("/update")
    public boolean update(@RequestBody DataKafkaTemplate dataCenter) {
        return dataKafkaTemplateService.updateById(dataCenter);
    }
    
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Integer id) {
        return dataKafkaTemplateService.removeById(id);
    }
    
} 